package com.liuheqiao.sushegaunli.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.liuheqiao.sushegaunli.R;
import com.liuheqiao.sushegaunli.VideoPlayerActivity;

public class BusinessFragment extends Fragment {
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_business, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        // 设置安全培训视频的点击事件
        LinearLayout llSafetyTraining = view.findViewById(R.id.ll_safety_training);
        
        if (llSafetyTraining != null) {
            Log.d("BusinessFragment", "Safety training view found");
            llSafetyTraining.setOnClickListener(v -> {
                // 添加Toast提示和日志
                Toast.makeText(requireContext(), "正在打开视频...", Toast.LENGTH_SHORT).show();
                Log.d("BusinessFragment", "Safety training video clicked");
                
                try {
                    String videoPath = "android.resource://" + requireContext().getPackageName() + "/" + R.raw.video2;
                    Intent intent = new Intent(requireContext(), VideoPlayerActivity.class);
                    intent.putExtra("video_url", videoPath);
                    startActivity(intent);
                } catch (Exception e) {
                    Log.e("BusinessFragment", "Error starting VideoPlayerActivity", e);
                    Toast.makeText(requireContext(), "打开视频失败: " + e.getMessage(), Toast.LENGTH_SHORT).show();
                }
            });
        } else {
            Log.e("BusinessFragment", "Safety training view not found");
        }
    }
} 